package com.yupi.springbootinit.controller;

import com.yupi.springbootinit.common.BaseResponse;
import com.yupi.springbootinit.common.DeleteRequest;
import com.yupi.springbootinit.common.ResultUtils;
import com.yupi.springbootinit.model.dto.qa.QaInspectionInstrumentAddRequest;
import com.yupi.springbootinit.model.dto.qa.QaInspectionInstrumentQueryRequest;
import com.yupi.springbootinit.model.dto.qa.QaInspectionInstrumentUpdateRequest;
import com.yupi.springbootinit.model.entity.QaInspectionInstrument;
import com.yupi.springbootinit.service.QaInspectionInstrumentService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * 检验仪器接口
 *
 * @author zhang
 * @date 2024/02/25
 */
@RestController
@RequestMapping("/qa/inspection-instrument")
public class QaInspectionInstrumentController {

    @Resource
    private QaInspectionInstrumentService qaInspectionInstrumentService;

    // region 增删改查

    /**
     * 创建
     *
     * @param qaInspectionInstrumentAddRequest
     * @return
     */
    @PostMapping("/add")
    public BaseResponse<Long> addQaInspectionInstrument(@RequestBody QaInspectionInstrumentAddRequest qaInspectionInstrumentAddRequest) {
        long newQaInspectionInstrumentId = qaInspectionInstrumentService.addQaInspectionInstrument(qaInspectionInstrumentAddRequest);
        return ResultUtils.success(newQaInspectionInstrumentId);
    }

    /**
     * 删除
     *
     * @param deleteRequest
     * @return
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteQaInspectionInstrument(@RequestBody DeleteRequest deleteRequest) {
        boolean b = qaInspectionInstrumentService.deleteQaInspectionInstrument(deleteRequest);
        return ResultUtils.success(b);
    }

    /**
     * 更新
     *
     * @param qaInspectionInstrumentUpdateRequest
     * @return
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateQaInspectionInstrument(@RequestBody QaInspectionInstrumentUpdateRequest qaInspectionInstrumentUpdateRequest) {
        boolean b = qaInspectionInstrumentService.updateQaInspectionInstrument(qaInspectionInstrumentUpdateRequest);
        return ResultUtils.success(b);
    }

    /**
     * 根据 id 获取
     *
     * @param id
     * @return
     */
    @GetMapping("/get")
    public BaseResponse<QaInspectionInstrument> getQaInspectionInstrumentById(long id) {
        QaInspectionInstrument qaInspectionInstrument = qaInspectionInstrumentService.getQaInspectionInstrumentById(id);
        return ResultUtils.success(qaInspectionInstrument);
    }

    /**
     * 获取列表
     *
     * @param qaInspectionInstrumentQueryRequest
     * @return
     */
    @GetMapping("/list")
    public BaseResponse<List<QaInspectionInstrument>> listQaInspectionInstrument(QaInspectionInstrumentQueryRequest qaInspectionInstrumentQueryRequest) {
        List<QaInspectionInstrument> qaInspectionInstrumentList = qaInspectionInstrumentService.listQaInspectionInstrument(qaInspectionInstrumentQueryRequest);
        return ResultUtils.success(qaInspectionInstrumentList);
    }

    /**
     * 分页获取列表
     *
     * @param qaInspectionInstrumentQueryRequest
     * @return
     */
    @GetMapping("/list/page")
    public BaseResponse<Page<QaInspectionInstrument>> listQaInspectionInstrumentByPage(QaInspectionInstrumentQueryRequest qaInspectionInstrumentQueryRequest) {
        Page<QaInspectionInstrument> qaInspectionInstrumentPage = qaInspectionInstrumentService.listQaInspectionInstrumentByPage(qaInspectionInstrumentQueryRequest);
        return ResultUtils.success(qaInspectionInstrumentPage);
    }

    // endregion
}